package mamikeji.liaowa.ui.activity.notice;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.PushMessage;
import mamikeji.liaowa.db.PushMessageManager;
import mamikeji.liaowa.ui.activity.BaseActivity;
import mamikeji.liaowa.ui.adapter.Notice_systemAdapter;
import mamikeji.liaowa.utils.MultiStateView;
import mamikeji.liaowa.widget.slidelistview.SilderListView;

public class Notice_SystemActivity extends BaseActivity {
    @BindView(R.id.multiStateView_Notice_System)
    MultiStateView multiStateViewNoticeSystem;
    @BindView(R.id.listView_System)
    SilderListView listViewSystem;
    private Notice_systemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice_system);
        ButterKnife.bind(this);
        getBase();
        setTitleLeftBtn();
        setTitleName(R.string.notice_system_name);
        setTitleRightBtn(R.string.notice_empty, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (adapter != null) {
                    adapter.clear();
                }
            }
        });

        init();
    }

    private void init() {
        List<PushMessage> list = PushMessageManager.queryAll();

        if (list != null && list.size() > 0) {
            multiStateViewNoticeSystem.setViewState(MultiStateView.VIEW_STATE_CONTENT);

            adapter = new Notice_systemAdapter(list, this);
            listViewSystem.setAdapter(adapter);
            listViewSystem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    PushMessage pushMessage = adapter.getItem(i);
                    pushMessage.setIsRead("true");
                    PushMessageManager.update(pushMessage);
                }
            });
            adapter.setOnItemClickListener(new Notice_systemAdapter.OnItemClickListener() {
                @Override
                public void onDeleteClick(int id) {
                    adapter.remove(id);
                }
            });
        }else {
            multiStateViewNoticeSystem.setViewState(MultiStateView.VIEW_STATE_EMPTY);
        }
    }
}
